package org.dolphin.entity.ar;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import org.dolphin.base.constant.DatabaseAttribute;
import org.dolphin.entity.customer.Customer;
import org.dolphin.entity.interceptor.Auditable;
import org.dolphin.entity.misc.DueDatePeriod;
import org.dolphin.entity.security.User;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "AR_SALES_INVOICE_HEADER", uniqueConstraints = {@UniqueConstraint(columnNames = {"INVOICE_NO"}, name = "UQ_AR_SALES_INVOICE_HEADER_INVOICE_NO")})
public class SalesInvoiceHeader implements Serializable, Auditable {
  private static final long serialVersionUID = 3256039753566403287L;
  private String id;
  private String invoiceNo;
  private Date invoiceDate;
  private Long version;
  private User createdBy;
  private User updatedBy;
  private Date createdDate;
  private Date updatedDate;
  private Customer customer;
  private Date dueDate;
  private BigDecimal total;
  private BigDecimal subtotal;
  private BigDecimal roundingAmount;
  private String remarks;
  private DueDatePeriod dueDatePeriod;

  @Override
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "CREATED_BY", nullable = false)
  @ForeignKey(name = "FK_AR_SALES_INVOICE_HEADER_CREATED_BY")
  public User getCreatedBy() {
    return createdBy;
  }

  @Override
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "CREATED_DATE", nullable = false)
  public Date getCreatedDate() {
    return createdDate;
  }

  @ManyToOne(fetch = FetchType.LAZY, optional = false)
  @JoinColumn(name = "CUSTOMER_ID", nullable = false)
  @ForeignKey(name = "FK_AR_SALES_INVOICE_HEADER_CUSTOMER_ID")
  public Customer getCustomer() {
    return customer;
  }

  @Temporal(TemporalType.DATE)
  @Column(name = "DUE_DATE", nullable = false)
  public Date getDueDate() {
    return dueDate;
  }

  @ManyToOne(fetch = FetchType.LAZY, optional = false)
  @JoinColumn(name = "DUE_DATE_PERIOD_ID", nullable = false)
  @ForeignKey(name = "FK_AR_SALES_INVOICE_HEADER_DUE_DATE_PERIOD_ID")
  public DueDatePeriod getDueDatePeriod() {
    return dueDatePeriod;
  }

  @Id
  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "org.dolphin.base.id.generator.CustomUUIDGenerator")
  @Column(name = "ID", nullable = false, length = DatabaseAttribute.ID_LENGTH)
  public String getId() {
    return id;
  }

  @Temporal(TemporalType.DATE)
  @Column(name = "INVOICE_DATE", nullable = false)
  public Date getInvoiceDate() {
    return invoiceDate;
  }

  @Column(name = "INVOICE_NO", nullable = false, length = 255)
  public String getInvoiceNo() {
    return invoiceNo;
  }

  @Column(name = "REMARKS", nullable = true, length = 1000)
  public String getRemarks() {
    return remarks;
  }

  @Column(name = "ROUNDING_AMOUNT", nullable = false)
  public BigDecimal getRoundingAmount() {
    return roundingAmount;
  }

  @Column(name = "SUBTOTAL", nullable = false)
  public BigDecimal getSubtotal() {
    return subtotal;
  }

  @Column(name = "TOTAL", nullable = false)
  public BigDecimal getTotal() {
    return total;
  }

  @Override
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "UPDATED_BY", nullable = true)
  @ForeignKey(name = "FK_AR_SALES_INVOICE_HEADER_UPDATED_BY")
  public User getUpdatedBy() {
    return updatedBy;
  }

  @Override
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "UPDATED_DATE", nullable = false)
  public Date getUpdatedDate() {
    return updatedDate;
  }

  @Version
  @Column(name = "VERSION_NO", nullable = false)
  public Long getVersion() {
    return version;
  }

  @Override
  public void setCreatedBy(User createdBy) {
    this.createdBy = createdBy;
  }

  @Override
  public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
  }

  public void setCustomer(Customer customer) {
    this.customer = customer;
  }

  public void setDueDate(Date dueDate) {
    this.dueDate = dueDate;
  }

  public void setDueDatePeriod(DueDatePeriod dueDatePeriod) {
    this.dueDatePeriod = dueDatePeriod;
  }

  public void setId(String id) {
    this.id = id;
  }

  public void setInvoiceDate(Date invoiceDate) {
    this.invoiceDate = invoiceDate;
  }

  public void setInvoiceNo(String invoiceNo) {
    this.invoiceNo = invoiceNo;
  }

  public void setRemarks(String remarks) {
    this.remarks = remarks;
  }

  public void setRoundingAmount(BigDecimal roundingAmount) {
    this.roundingAmount = roundingAmount;
  }

  public void setSubtotal(BigDecimal subtotal) {
    this.subtotal = subtotal;
  }

  public void setTotal(BigDecimal total) {
    this.total = total;
  }

  @Override
  public void setUpdatedBy(User updatedBy) {
    this.updatedBy = updatedBy;
  }

  @Override
  public void setUpdatedDate(Date updatedDate) {
    this.updatedDate = updatedDate;
  }

  public void setVersion(Long version) {
    this.version = version;
  }
}
